      SUBROUTINE PLT_READ_NOISE
     &          (lu_grd,
     &           file_id,n_model,
     &           freq,month,day,year,UT,bandw,ralt,adjny,vsd_flag,
     &           mxpath,nrpath,bearing,rhomax,rxlat,rxlon,
     &           mxprm,nrprm,param,nrcmp,mxlat,nrlat,mxlon,nrlon,
     &           area_id,xlat1,xlon1,xlat2,xlon2,
     &           amp_grd,sig_grd,vsd_grd,
     &           data_format)

c***********************************************************************

c Reads file generated by noise programs

c***********************************************************************

c Parameters:

c     lu_grd        logical unit for grid data

c     file_id       file identification; 120 characters

c     n_model       noise model name: ITSN, NTIA or LNP
c     month         month number; January is 1
c     day           day of the month
c     year          year
c     UT            Universal Time; hours and minutes
c     bandw         band width; Hz
c     ralt          receiver altitude; km
c     adjny         adjustment factor for horizontal noise; dB
c     Vsd_flag      indicates that the grid file contained V sub d

c     mxpath        maximum number of paths
c     nrpath                number of paths
c     bearing                         bearings angles of the paths
c     rhomax                          maximum  ranges of the paths
c     rxlat                           receiver latitudes
c     rxlon                           receiver longitudes

c     mxprm         maximum number of parameters
c     nrprm                 number of parameters
c     param                           parameters

c     nrcmp         number of components of noise

c     mxlon         maximum number of points in longitude
c     mxlat         maximum number of points in latitude
c     nrlon         number of points in longitude to be used
c     nrlat         number of points in latitude  to be used

c     area_id       op area identification;   8 characters

c     xlat1         lower bound of the op area; degrees N
c     xlon1         right bound of the op area; degrees W
c     xlat2         upper bound of the op area; degrees N
c     xlon2         left  bound of the op area; degrees W

c     amp_grd       grid of noise amplitudes
c     sig_grd       grid of noise standard deviations
c     Vsd_grd       grid of noise V sub d

c     data_format   'a' if data is in ASCII format
c                   'b' if data is in BINARY format
c                   'c' if data is in C-BINARY format

c***********************************************************************

c  Change history:

c     29 Jan 94     Added ASCII/BINARY option.

c     06 Apr 94     Dropped test on YEAR and DAY during search for data.

c     27 Oct 95     Changed to use lwpc_LUN.cmn to set logical units.

c     04 Nov 95     Added parameters to the error print out.

c     30 Jan 96     Added coding for V sub d.

c     05 Feb 96     Dropped test on NRLAT and NRLON when the noise model
c                   is LNP.

c     15 Aug 98     Added C-Binary format; improved error tests and
c                   messages.

c*******************!***************************************************

c     LWPC parameters
      include      'lwpc_cfg.cmn'
      include      'lwpc_lun.cmn'
      include      'grd_data.cmn'

      character*(*) data_format
      character*  4 n_model
      character*  8 archive,prgm_id,nmodelt,nmodelx
      character* 20 xmtr_id,path_id,area_id,areaidx
      character* 40 prfl_id
      character* 80 case_id
      character*120 file_id(3)
      character*200 error_msg
      logical       begin_file,end_file,no_matches
      integer       lu_grd,print_grd/0/,
     &              day,year,UT,UTx,
     &              str_length
      real          bearing(mxpath),rhomax(mxpath),
     &              rxlat(mxpath),rxlon(mxpath),
     &              amp_grd(mxlon,mxlat,2),sig_grd(mxlon,mxlat,2),
     &              vsd_grd(mxlon,mxlat,2),
     &              param(mxprm)

      nmodelt=n_model
      call STR_LOWER (nmodelt,0,0)

      if (data_format(1:1) .eq. 'C' .or.
     &    data_format(1:1) .eq. 'c') then

c        There is only one set of data in each C-Binary file
         call READ_C_GRD
     &       (lu_grd,print_hdr,print_grd,
     &        archive,file_id,prgm_id,
     &        case_id,prfl_id,
     &        xmtr_id,freqx,tlatx,tlonx,
     &        path_id,oplat1,oplon1,oplat2,oplon2,
     &        nrpath,bearing,rhomax,rxlat,rxlon,
     &        nrprm,nrcmp,nrlwf,param,
     &        areaidx,xlat1x,xlon1x,xlat2x,xlon2x,
     &        nrlatx,nrlonx,
     &        amp_grd(1,1,1),sig_grd(1,1,1),
     &        begin_file,end_file)

         nmodelx=prfl_id
         call STR_LOWER (nmodelx,0,0)

         raltx =param( 6)
         monthx=param( 7)
         dayx  =param( 8)
         yearx =param( 9)
         UTx   =param(10)
         bandwx=param(11)
         adjnx =param(12)

         no_matches=.true.
         if (freq  .eq. freqx  .and. bandw .eq. bandwx .and.
     &       month .eq. monthx .and. UT    .eq. UTx    .and.
     &       xlat1 .eq. xlat1x .and. xlon1 .eq. xlon1x .and.
     &       xlat2 .eq. xlat2x .and. xlon2 .eq. xlon2x .and.
     &       nrlat .eq. nrlatx .and. nrlon .eq. nrlonx) then

c           A match has been found
            no_matches=.false.

            ralt =raltx
            adjny=adjnx
         end if
         if (no_matches) then

c           No match was found
            write(lwpcLOG_lun,
     &          '(''ERROR [PLT_READ_NOISE]:''/
     &            ''The data requested was not found in '',
     &            ''the grid file.'')')
            write(lwpcLOG_lun,
     &          '(''Parameters requested:'')')
            write(lwpcLOG_lun,
     &          '(''model,freq,mon,UT,bandw,''
     &            ''xlat1,xlon1,xlat2,xlon2,nrlat,nrlon,''
     &            ''area_id'')')
            write(lwpcLOG_lun,
     &          '(a,1x,f5.1,i5,i6,f7.1,2(f7.1,f8.1),2i4,1x,a)')
     &            nmodelt,freq,month,UT,bandw,
     &            xlat1,xlon1,xlat2,xlon2,nrlat,nrlon,
     &            area_id(:STR_LENGTH(area_id))
            write(lwpcLOG_lun,
     &          '(''Parameters found:'')')
            write(lwpcLOG_lun,
     &          '(''model,freq,mon,UT,bandw,''
     &            ''xlat1,xlon1,xlat2,xlon2,nrlat,nrlon,''
     &            ''area_id'')')
            write(lwpcLOG_lun,
     &          '(a,1x,f5.1,i5,i6,f7.1,2(f7.1,f8.1),2i4,1x,a)')
     &            nmodelx,freqx,monthx,UTx,bandwx,
     &            xlat1x,xlon1x,xlat2x,xlon2x,nrlatx,nrlonx,
     &            areaidx(:STR_LENGTH(areaidx))
            write(error_msg,
     &          '(''ERROR [PLT_READ_NOISE]: '',
     &            ''The data requested was not found in '',
     &            ''the grid file.'')')
            call LWPC_ERROR ('ERROR',error_msg)
         end if
cxxcDEBUG
cxx         write(lwpcLOG_lun,
cxx     &       '(''DEBUG [PLT_READ_NOISE]:'')')
cxx         write(lwpcLOG_lun,
cxx     &       '(''model,freq,mon,UT,bandw,''
cxx     &         ''xlat1,xlon1,xlat2,xlon2,nrlat,nrlon,''
cxx     &         ''area_id'')')
cxx         write(lwpcLOG_lun,
cxx     &       '(a,1x,f5.1,i5,i6,f7.1,2(f7.1,f8.1),2i4,1x,a)')
cxx     &         nmodelx,freqx,monthx,UTx,bandwx,
cxx     &         xlat1x,xlon1x,xlat2x,xlon2x,nrlatx,nrlonx,
cxx     &         areaidx(:STR_LENGTH(areaidx))
cxx
cxx         do i=1,nrlonx
cxx            do j=1,nrlatx
cxx               write(lwpcLOG_lun,*)
cxx     &               i,j,amp_grd(i,j,1),sig_grd(i,j,1)
cxx            end do
cxx         end do
      else

         call READ_HDR
     &       (lu_grd,print_grd,
     &        archive,file_id,prgm_id,
     &        case_id,prfl_id,
     &        xmtr_id,freqx,tlatx,tlonx,
     &        path_id,oplat1,oplon1,oplat2,oplon2,
     &        mxpath,nrpath,bearing,rhomax,rxlat,rxlon,
     &        begin_file,end_file,
     &        data_format)

         nmodelx=prfl_id
         call STR_LOWER (nmodelx,0,0)

         no_matches=.true.
         do while (no_matches .and. .not.end_file)

            call READ_GRD
     &          (lu_grd,print_grd,
     &           mxprm,nrprm,param,nrcmpx,nrlwf,
     &           areaidx,xlat1x,xlon1x,xlat2x,xlon2x,
     &           mxlat,nrlatx,mxlon,nrlonx,
     &           amp_grd(1,1,1),sig_grd(1,1,1),
     &           begin_file,end_file,
     &           data_format)

            if (.not.end_file) then

c              Check for extra arrays
               if (nrprm .gt. 12 .and. param(13) .gt. 0.) then

                  nrgrd=param(13)

c                 Read the extra arrays;
c                 note that sig_grd in this call is just a place holder,
c                 the existing array is not changed.
                  do ngrd=1,nrgrd

                     call READ_GRD
     &                   (lu_grd,print_grd,
     &                    mxprm,nrprm,param,nrcmpx,nrlwf,
     &                    areaidx,xlat1x,xlon1x,xlat2x,xlon2x,
     &                    mxlat,nrlatx,mxlon,nrlonx,
     &                    vsd_grd(1,1,1),sig_grd(1,1,1),
     &                    begin_file,end_file,
     &                    data_format)
                  end do
               end if

               if (nrcmpx .gt. 1) then

                  do ncmp=2,nrcmpx

                     call READ_GRD
     &                   (lu_grd,print_grd,
     &                    mxprm,nrprm,param,nrcmpx,nrlwf,
     &                    areaidx,xlat1x,xlon1x,xlat2x,xlon2x,
     &                    mxlat,nrlatx,mxlon,nrlonx,
     &                    amp_grd(1,1,ncmp),sig_grd(1,1,ncmp),
     &                    begin_file,end_file,
     &                    data_format)

                     if (nrprm .gt. 12 .and. param(13) .gt. 0.) then

                        do ngrd=1,nrgrd

                           call READ_GRD
     &                         (lu_grd,print_grd,
     &                          mxprm,nrprm,param,nrcmpx,nrlwf,
     &                          areaidx,xlat1x,xlon1x,xlat2x,xlon2x,
     &                          mxlat,nrlatx,mxlon,nrlonx,
     &                          vsd_grd(1,1,ncmp),sig_grd(1,1,ncmp),
     &                          begin_file,end_file,
     &                          data_format)
                        end do
                     end if
                  end do
               end if

               monthx=param( 7)
               UTx   =param(10)
               bandwx=param(11)

               if (nmodelt(:3) .eq. 'lnp') then

                  if (freq  .eq. freqx  .and. bandw .eq. bandwx .and.
     &                month .eq. monthx .and. UT    .eq. UTx  ) then

c                    A match has been found
                     no_matches=.false.

c                    Return the grid size
                     nrlat=nrlatx
                     nrlon=nrlonx

                     nrcmp=nrcmpx
                     ralt =param( 6)
                     month=param( 7)
                     day  =param( 8)
                     year =param( 9)
                     UT   =param(10)
                     bandw=param(11)
                     adjny=param(12)

                     if (nrprm .gt. 12) then
                        vsd_flag=param(13)
                     else
                        vsd_flag=0.
                     end if
                  end if
               else

                  if (freq  .eq. freqx  .and. bandw .eq. bandwx .and.
     &                month .eq. monthx .and. UT    .eq. UTx    .and.
     &                xlat1 .eq. xlat1x .and. xlon1 .eq. xlon1x .and.
     &                xlat2 .eq. xlat2x .and. xlon2 .eq. xlon2x .and.
     &                nrlat .eq. nrlatx .and. nrlon .eq. nrlonx) then

c                    A match has been found
                     no_matches=.false.

                     nrcmp=nrcmpx
                     ralt =param( 6)
                     month=param( 7)
                     day  =param( 8)
                     year =param( 9)
                     UT   =param(10)
                     bandw=param(11)
                     adjny=param(12)

                     if (nrprm .gt. 12) then
                        vsd_flag=param(13)
                     else
                        vsd_flag=0.
                     end if
                  end if
               end if
            end if
         end do

         if (no_matches) then

c           Error message
            write(lwpcLOG_lun,
     &          '(''ERROR [PLT_READ_NOISE]:''/
     &            ''The data requested was not found in '',
     &            ''the grid file.'')')
            write(lwpcLOG_lun,
     &          '(''Parameters requested:'')')
            write(lwpcLOG_lun,
     &          '(''model,freq,mon,UT,bandw,''
     &            ''xlat1,xlon1,xlat2,xlon2,nrlat,nrlon,''
     &            ''area_id'')')
            write(lwpcLOG_lun,
     &          '(a,1x,f5.1,i5,i6,f7.1,2(f7.1,f8.1),2i4,1x,a)')
     &            nmodelt,freq,month,UT,bandw,
     &            xlat1,xlon1,xlat2,xlon2,nrlat,nrlon,
     &            area_id(:STR_LENGTH(area_id))
            write(lwpcLOG_lun,
     &          '(''Parameters found:'')')
            write(lwpcLOG_lun,
     &          '(''model,freq,mon,UT,bandw,''
     &            ''xlat1,xlon1,xlat2,xlon2,nrlat,nrlon,''
     &            ''area_id'')')

            REWIND(lu_grd)

            call READ_HDR
     &          (lu_grd,print_grd,
     &           archive,file_id,prgm_id,
     &           case_id,prfl_id,
     &           xmtr_id,freqx,tlatx,tlonx,
     &           path_id,oplat1,oplon1,oplat2,oplon2,
     &           mxpath,nrpath,bearing,rhomax,rxlat,rxlon,
     &           begin_file,end_file,
     &           data_format)

            nmodelx=prfl_id
            call STR_LOWER (nmodelx,0,0)

            do while (.not.end_file)

               call READ_GRD
     &             (lu_grd,print_grd,
     &              mxprm,nrprm,param,nrcmpx,nrgrd,
     &              areaidx,xlat1x,xlon1x,xlat2x,xlon2x,
     &              mxlat,nrlatx,mxlon,nrlonx,
     &              amp_grd(1,1,1),sig_grd(1,1,1),
     &              begin_file,end_file,
     &              data_format)

               if (.not.end_file) then

                  if (nrprm .gt. 12 .and. param(13) .gt. 0.) then

                     nrgrd=param(13)
                     do ngrd=1,nrgrd

                        call READ_GRD
     &                      (lu_grd,print_grd,
     &                       mxprm,nrprm,param,nrcmpx,nrgrd,
     &                       areaidx,xlat1x,xlon1x,xlat2x,xlon2x,
     &                       mxlat,nrlatx,mxlon,nrlonx,
     &                       vsd_grd(1,1,1),sig_grd(1,1,1),
     &                       begin_file,end_file,
     &                       data_format)
                     end do
                  end if
                  if (nrcmpx .gt. 1) then

                     do ncmp=2,nrcmpx

                        call READ_GRD
     &                      (lu_grd,print_grd,
     &                       mxprm,nrprm,param,nrcmpx,nrlwf,
     &                       areaidx,xlat1x,xlon1x,xlat2x,xlon2x,
     &                       mxlat,nrlatx,mxlon,nrlonx,
     &                       amp_grd(1,1,ncmp),sig_grd(1,1,ncmp),
     &                       begin_file,end_file,
     &                       data_format)

                        if (nrprm .gt. 12 .and. param(13) .gt. 0.) then

                           do ngrd=1,nrgrd

                              call READ_GRD
     &                            (lu_grd,print_grd,
     &                             mxprm,nrprm,param,nrcmpx,nrlwf,
     &                             areaidx,xlat1x,xlon1x,xlat2x,xlon2x,
     &                             mxlat,nrlatx,mxlon,nrlonx,
     &                             vsd_grd(1,1,ncmp),sig_grd(1,1,ncmp),
     &                             begin_file,end_file,
     &                             data_format)
                           end do
                        end if
                     end do
                  end if

                  monthx =param( 7)
                  UTx    =param(10)
                  bandwx =param(11)

                  write(lwpcLOG_lun,
     &                '(a,1x,f5.1,i5,i6,f7.1,2(f7.1,f8.1),2i4,1x,a)')
     &                  nmodelx,freqx,monthx,UTx,bandwx,
     &                  xlat1x,xlon1x,xlat2x,xlon2x,nrlatx,nrlonx,
     &                  areaidx(:STR_LENGTH(areaidx))
               end if
            end do

c           STOP execution
            write(error_msg,
     &          '(''ERROR [PLT_READ_NOISE]: '',
     &            ''The data requested was not found in '',
     &            ''the grid file.'')')
            call LWPC_ERROR ('ERROR',error_msg)
         end if
      end if
      REWIND(lu_grd)
      RETURN
      END      ! PLT_READ_NOISE
